<?php

$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */

$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 

$installer->run("
CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_aux')}` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `product_id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `real_order_id` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  `percent` decimal(10,2) NOT NULL,
  `amount_earned` decimal(10,2) NOT NULL,
  `amount_owed` decimal(10,2) NOT NULL,
  `cleared_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `real_order_id` (`real_order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity')}` (
  `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `entity_type_id` smallint(8) unsigned NOT NULL DEFAULT '0',
  `attribute_set_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `website_id` smallint(5) unsigned DEFAULT NULL,
  `email` varchar(255) NOT NULL DEFAULT '',
  `group_id` smallint(3) unsigned NOT NULL DEFAULT '0',
  `increment_id` varchar(50) NOT NULL DEFAULT '',
  `parent_id` int(10) unsigned NOT NULL DEFAULT '0',
  `store_id` smallint(5) unsigned DEFAULT '0',
  `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `is_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`entity_id`),
  KEY `FK_MARKETPLACEPARTNER_ENTITY_STORE` (`store_id`),
  KEY `IDX_ENTITY_TYPE` (`entity_type_id`),
  KEY `IDX_AUTH` (`email`,`website_id`),
  KEY `FK_MARKETPLACEPARTNER_WEBSITE` (`website_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Customer Entityies' AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_additionalinfo')}` (
  `userid` int(11) NOT NULL,
  `address` text NOT NULL,
  `postalcode` text NOT NULL,
  `city` text NOT NULL,
  `area` text NOT NULL,
  `addurl` text NOT NULL,
  `price` int(11) NOT NULL,
  `additional` text NOT NULL,
  `mobile` text NOT NULL,
  `addinfoid` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`addinfoid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_data')}` (
  `index` int(11) NOT NULL AUTO_INCREMENT,
  `producttype` varchar(255) NOT NULL,
  `producttypecustom` varchar(255) NOT NULL,
  `mageproductid` int(11) NOT NULL,
  `userid` int(11) NOT NULL,
  `wstoreids` int(11) NOT NULL,
  `sku` varchar(255) NOT NULL,
  `customerpartnerproductid` varchar(255) NOT NULL,
  `category` varchar(255) NOT NULL,
  `shippingtype` varchar(255) NOT NULL,
  `shippingamount` varchar(255) NOT NULL,
  `status` int(11) NOT NULL,
  PRIMARY KEY (`index`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_datafeedback')}` (
  `feedid` int(11) NOT NULL AUTO_INCREMENT,
  `userid` smallint(6) NOT NULL,
  `useremail` varchar(255) NOT NULL,
  `status` smallint(6) NOT NULL,
  `proownerid` smallint(6) NOT NULL,
  `feedprice` smallint(6) NOT NULL,
  `feedvalue` smallint(6) NOT NULL,
  `feedquality` smallint(6) NOT NULL,
  `feednickname` varchar(255) NOT NULL,
  `feedsummary` text NOT NULL,
  `feedreview` text NOT NULL,
  `createdat` datetime NOT NULL,
  PRIMARY KEY (`feedid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_datapayment')}` (
 `autoid` int(11) NOT NULL AUTO_INCREMENT,
  `userid` int(11) NOT NULL,
  `paymentsource` varchar(255) NOT NULL,
  PRIMARY KEY (`autoid`),
  UNIQUE KEY `userid` (`userid`)
)  ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_datetime')}` (
  `value_id` int(11) NOT NULL AUTO_INCREMENT,
  `entity_type_id` smallint(8) unsigned NOT NULL DEFAULT '0',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `entity_id` int(10) unsigned NOT NULL DEFAULT '0',
  `value` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`value_id`),
  KEY `FK_MARKETPLACEPARTNER_DATETIME_ENTITY_TYPE` (`entity_type_id`),
  KEY `FK_MARKETPLACEPARTNER_DATETIME_ATTRIBUTE` (`attribute_id`),
  KEY `FK_MARKETPLACEPARTNER_DATETIME_ENTITY` (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;




CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_decimal')}` (
  `value_id` int(11) NOT NULL AUTO_INCREMENT,
  `entity_type_id` smallint(8) unsigned NOT NULL DEFAULT '0',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `entity_id` int(10) unsigned NOT NULL DEFAULT '0',
  `value` decimal(12,4) NOT NULL DEFAULT '0.0000',
  PRIMARY KEY (`value_id`),
  KEY `FK_MARKETPLACEPARTNER_DECIMAL_ENTITY_TYPE` (`entity_type_id`),
  KEY `FK_MARKETPLACEPARTNER_DECIMAL_ATTRIBUTE` (`attribute_id`),
  KEY `FK_MARKETPLACEPARTNER_DECIMAL_ENTITY` (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_int')}` (
  `value_id` int(11) NOT NULL AUTO_INCREMENT,
  `entity_type_id` smallint(8) unsigned NOT NULL DEFAULT '0',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `entity_id` int(10) unsigned NOT NULL DEFAULT '0',
  `value` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`value_id`),
  KEY `FK_MARKETPLACEPARTNER_INT_ENTITY_TYPE` (`entity_type_id`),
  KEY `FK_MARKETPLACEPARTNER_INT_ATTRIBUTE` (`attribute_id`),
  KEY `FK_MARKETPLACEPARTNER_INT_ENTITY` (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_saleperpartner')}` (
  `autoid` int(11) NOT NULL AUTO_INCREMENT,
  `mageuserid` int(11) NOT NULL,
  `totalsale` int(11) NOT NULL,
  `amountrecived` int(11) NOT NULL,
  `amountpaid` int(11) NOT NULL,
  `amountremain` int(11) NOT NULL,
  `commision` decimal(10,0) NOT NULL,
  PRIMARY KEY (`autoid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_saleslist')}` (
  `autoid` int(11) NOT NULL AUTO_INCREMENT,
  `mageproid` varchar(255) NOT NULL,
  `mageorderid` varchar(255) NOT NULL,
  `magerealorderid` varchar(255) NOT NULL,
  `magequantity` varchar(255) NOT NULL,
  `mageproownerid` varchar(255) NOT NULL,
  `cpproid` varchar(255) NOT NULL,
  `magebuyerid` varchar(255) NOT NULL,
  `mageproprice` varchar(255) NOT NULL,
  `mageproname` varchar(255) NOT NULL,
  `totalamount` varchar(255) NOT NULL,
  `totalcommision` varchar(255) NOT NULL,
  `actualparterprocost` varchar(255) NOT NULL,
  `cleared_at` datetime NOT NULL,
  PRIMARY KEY (`autoid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_text')}` (
  `value_id` int(11) NOT NULL AUTO_INCREMENT,
  `entity_type_id` smallint(8) unsigned NOT NULL DEFAULT '0',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `entity_id` int(10) unsigned NOT NULL DEFAULT '0',
  `value` text NOT NULL,
  PRIMARY KEY (`value_id`),
  KEY `FK_MARKETPLACEPARTNER_TEXT_ENTITY_TYPE` (`entity_type_id`),
  KEY `FK_MARKETPLACEPARTNER_TEXT_ATTRIBUTE` (`attribute_id`),
  KEY `FK_MARKETPLACEPARTNER_TEXT_ENTITY` (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_userdata')}` (
   `autoid` smallint(6) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(255) NOT NULL,
  `lastname` varchar(255) NOT NULL,
  `wantpartner` smallint(6) NOT NULL,
  `partnerstatus` varchar(255) NOT NULL DEFAULT 'Deafult User',
  `email` varchar(255) NOT NULL,
  `mageuserid` int(11) NOT NULL,
  `twitterid` varchar(255) NOT NULL,
  `facebookid` varchar(255) NOT NULL,
  `bannerpic` text NOT NULL,
  `logopic` varchar(255) NOT NULL,
  `complocality` varchar(255) NOT NULL,
  `countrypic` varchar(255) NOT NULL,
  `compname` varchar(255) NOT NULL,
  `compdesi` text NOT NULL,
  `compdesihtml` text NOT NULL,
  `backgroundth` varchar(255) NOT NULL,
  PRIMARY KEY (`autoid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `{$this->getTable('marketplacepartner_entity_varchar')}` (
  `value_id` int(11) NOT NULL AUTO_INCREMENT,
  `entity_type_id` smallint(8) unsigned NOT NULL DEFAULT '0',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `entity_id` int(10) unsigned NOT NULL DEFAULT '0',
  `value` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`value_id`),
  KEY `FK_MARKETPLACEPARTNER_VARCHAR_ENTITY_TYPE` (`entity_type_id`),
  KEY `FK_MARKETPLACEPARTNER_VARCHAR_ATTRIBUTE` (`attribute_id`),
  KEY `FK_MARKETPLACEPARTNER_VARCHAR_ENTITY` (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


ALTER TABLE `{$this->getTable('marketplacepartner_entity')}`
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_ENTITY_STORE` FOREIGN KEY (`store_id`) REFERENCES `{$this->getTable('core_store')}` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_WEBSITE` FOREIGN KEY (`website_id`) REFERENCES `{$this->getTable('core_website')}` (`website_id`) ON DELETE SET NULL ON UPDATE CASCADE;


ALTER TABLE `{$this->getTable('marketplacepartner_entity_datetime')}`
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_DATETIME_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_DATETIME_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this->getTable('marketplacepartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_DATETIME_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this->getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `{$this->getTable('marketplacepartner_entity_decimal')}`
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_DECIMAL_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_DECIMAL_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this->getTable('marketplacepartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_DECIMAL_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this->getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `{$this->getTable('marketplacepartner_entity_int')}`
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_INT_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_INT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this->getTable('marketplacepartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_INT_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this->getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `{$this->getTable('marketplacepartner_entity_text')}`
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_TEXT_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_TEXT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this->getTable('marketplacepartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_TEXT_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this->getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `{$this->getTable('marketplacepartner_entity_varchar')}`
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_VARCHAR_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_VARCHAR_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this->getTable('marketplacepartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `FK_MARKETPLACEPARTNER_VARCHAR_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this->getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
	");
$installer->installEntities();

$installer->endSetup();
